/*
 * =====================================================================================
 *
 *       Filename:  messenger_back.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  29.08.2012 16:54:31
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  akoww (), 
 *   Organization:  
 *
 * =====================================================================================
 */

#include "messenger.hpp"

MessengerBack::MessengerBack ( void ) {

}

MessengerBack::~MessengerBack ( void ) {

}

void MessengerBack::appendMsg ( const std::string& msg, Person pers ) {
	if ( !checkSize() ) 
		resizeVec();

	m_what.push_back ( msg );
	if ( pers == ME )
		m_who.push_back ( true );
	else 
		m_who.push_back ( false );
}
void MessengerBack::appendMsg ( const char *msg, Person pers ) {
	const std::string buf ( msg );
	appendMsg ( buf, pers );
}

bool MessengerBack::checkSize ( void ) {
	if ( m_who.size() >= MAXLINES )
		return false;
	return true;
}

void MessengerBack::resizeVec ( void ) {
	
	std::vector<std::string>::const_iterator abuf_iter_start = m_what.end();
	std::vector<std::string>::const_iterator abuf_iter_end = m_what.end() - TRIMLINES ;
	std::vector<std::string> abuf ( abuf_iter_start, abuf_iter_end );

	std::vector<bool>::const_iterator bbuf_iter_start = m_who.end();
	std::vector<bool>::const_iterator bbuf_iter_end = m_who.end() - TRIMLINES ;
	std::vector<bool> bbuf ( bbuf_iter_start, bbuf_iter_end ) ;

	m_who.swap ( bbuf );
	m_what.swap ( abuf );
}
